//
//  YNRecentChatObejct.h
//  Messenger
//
//  Created by iOS on 15/2/11.
//  Copyright (c) 2015年 孙浪. All rights reserved.
//
//  最近会话实体类
//

#import <Foundation/Foundation.h>
#import "YNIMFrameworkTypedef.h"

@interface YNRecentChatObejct : NSObject

//对方no，群，个人，讨论组，广播 ，通知no
@property (nonatomic, strong)NSString *userNo;

//会话名字(主题：群，个人，讨论组的名称)
@property (nonatomic, strong)NSString *title;

//消息内容
@property (nonatomic, strong)NSString *content;

//消息类型(1:两人 2:讨论组 3：群组 4:广播 5:通知)
@property (nonatomic)        int       chatType;

/**
 *  方式方式，自己还是对方
 */
@property(nonatomic,assign)int masterRecentType;

//发送者名字
@property (nonatomic, strong)NSString *senderName;

//发送者帐号(自己或对方（个人对话时，senderNo==fromUserNo)
@property (nonatomic, strong)NSString *sendNo;

//收发时间
@property (nonatomic, strong)NSString *dataTime;

//置顶时间
@property (nonatomic, strong)NSString *topTime;

//头像URL
@property (nonatomic, strong)NSString *headUrl;

//头像本地路径
@property (nonatomic, strong)NSString *headLocalPath;

//具体消息内容
@property (nonatomic, strong)NSString *messageBody;

//语音ID2016-8-9jc添加
@property (nonatomic, strong) NSString * voiceId;
@property (nonatomic, copy) NSString *voicePath;//声音路径
@property (nonatomic, copy) NSString *voiceUrl;
@property (nonatomic, copy) NSString *voiceDuration;//声音时间

/*=================================解决消息列表卡顿问题新加入的字段=========================================*/
//用户的状态
@property(nonatomic,assign)YNUserStateType userState;
//gender性别1-男  2-女 3-保密
@property (nonatomic) int gender;
/*=================================end=========================================*/
/**
 2017-4-18jc添加
 *  谈论组，群管理员标示
 */
@property(nonatomic,strong)NSString * role;

/**
 2018-12-10Jc添加
 *  消息id
 */
@property(nonatomic,strong)NSString * packId;


/**
 *  2018-11-15JC添加
 增加艾特@标识
 0:默认没有@谁   1：有人@我  2：有全体消息
 */
@property(nonatomic,assign)NSInteger aitContactMark;


/**
 *  2018-11-15JC添加
 增加@艾特谁数组
 */
@property(nonatomic,strong)NSString * aitContactMarkArray;

/**
 * JC添加-用于测回消息判断
 *  YES：撤回,NO:正常消息
 */
@property(nonatomic,assign)BOOL isMessageWithdraw;

//是否置顶(0:不置顶  1：置顶)
@property (nonatomic)        int       isTop;

//未读条数(默认为0)
@property (nonatomic)        int       unReadCount;

//发送的状态(1.发送成功, 0:失败, 2:发送中， 3:草稿)
@property (nonatomic)        int       sendState;

//消息类型 (0.文本, 1.图片, 6. 文件, 7.富文本)
@property (nonatomic)        int       messageType;

//json序列化的一个数组, 包含图片, 文字, 头像
@property (nonatomic, strong)NSString *text;
//在列表里面的排序，用于消息通知消息展示时选在head图片
@property(nonatomic,strong)NSIndexPath *indexPath;

/**
 *  是否在拉取最新消息漫游
 */
@property(nonatomic,assign)BOOL isNewListPullData;
///通知和系统消息的more
@property(nonatomic,copy)NSString* more;

//创建历史消息表
+ (BOOL)createRecentChatTableInDatabase:(FMDatabase *)db;

//判断表里有没有与某某的会话
+ (BOOL)determineRecentChatTableWithUserNo:(NSString *)UserNo Database:(FMDatabase *)db;

//插入最近会话信息(表里没有这个会话，增加新的会话)
- (BOOL)insertRecentChatTableInDatabase:(FMDatabase *)db;

//更新最近会话信息(在会话列表界面，并且有与此人的会话，包括置顶什么的字段修改)
- (BOOL)updateRecentChatTableInDatabase:(FMDatabase *)db isFromRoamingSource:(BOOL)isRoaming;

/**
 2019-01 修改 查询所有最近会话消息列表数据
 
 @param db <#db description#>
 @param needScreenTop 是否需要赛选处理置顶消息
 @return 集合
 */
+ (NSArray<YNRecentChatObejct*> *)queryAllRecentChatTableInDatabase:(FMDatabase *)db needScreenTopChat:(BOOL)needScreenTop;

/**JC** 将isNewListPullData更新为YES，表示已经拉取过消息漫游 **/
+(BOOL)updateRecentNewListPullDataUnreadCountByOneWithUserNo:(NSString*)UserNo Database:(FMDatabase*)db;

//将UserNo未读消息的未读条数置为0，若UserNo 为nil，则将全部未读消息条数置为0
+ (BOOL)unReadNumberMakeZeroWithUserNo:(NSString *)UserNo Database:(FMDatabase *)db;
/**
 * 删除一个会话
 * UserNo 是对方的number
 * chatType 消息类型
 **/
+ (BOOL)deleteRecentForTableWithUserNo:(NSString *)UserNo ChatType:(int)ChatType database:(FMDatabase *)db;

//删除所有会话
+ (BOOL)deleteAllRecentWithDatabase:(FMDatabase *)db;

/**HX** 将userNo未读消息的未读数做加一或减一的更新 **/
+(BOOL)updateUserUnreadCountByOneWithUserNo:(NSString*)UserNo isAddOne:(BOOL)addOne Database:(FMDatabase*)db;

//--------------------------------------//-----------------------------------//------------------------------//-------------------------------//

//更新会话
+ (BOOL)updateRecentChatTableWithUseNo:(NSString *)UserNo sendTime:(NSString *)sendTime isSuccess:(int)messageState inDatabase:(FMDatabase *)db;
/**
 *  @brief  更改聊天记录标题
 *
 *  @param title  最近聊天记录标题
 */
+ (BOOL)updateRecentChatTitle:(NSString *)title byUserNo:(NSString *)userNo inDatabase:(FMDatabase *)db;

//根据ID查询一条最近会话
+ (YNRecentChatObejct *)queryRecentChatWithFriendId:(NSString *)friendId inDatabase:(FMDatabase *)db;

//根据packId查询本条信息
+ (NSArray *)queryRecentChatWithPackId:(NSString *)packId inDatabase:(FMDatabase *)db;

//只更新状态
+ (BOOL)updateMessageSendingStateWithDatabase:(FMDatabase *)db;

//根据userNo查询本条信息
+ (NSArray *)queryRecentChatWithUserNo:(NSString *)userNo inDatabase:(FMDatabase *)db;
//删除所有系统和通知公告消息
+ (BOOL)deleteRecentSystemAndInformChatWithdatabase:(FMDatabase *)db;

//获取当前UserID的未读消息记录
+ (int)queryUnReadWithUserNo:(NSString *)userNo inDatabase:(FMDatabase *)db;

/**
 修改撤回状态  2018.11.27jc添加
 
 @param chatId 对方id
 @param packId 消息id
 @param db db
 @return
 */
+(BOOL)updateRecentChatWithdrawWithChatId:(NSString *)chatId packId:(NSString *)packId inDatabase:(FMDatabase *)db;


@end
